home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / inventor / SpaceballViewer / MyColorWheel.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  6.2 KB  |  194 lines

  1. /*
  2.  * Copyright (c) 1990-94 Silicon Graphics, Inc.
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that the name of Silicon Graphics may not be used in any advertising or
  7.  * publicity relating to the software without the specific, prior written
  8.  * permission of Silicon Graphics.
  9.  *
  10.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
  11.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
  12.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  13.  *
  14.  * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  15.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
  16.  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE
  17.  * POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN
  18.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  19.  */
  20. //  -*- C++ -*-
  21.  
  22. /*
  23.  * Copyright (C) 1990-93   Silicon Graphics, Inc.
  24.  *
  25.  _______________________________________________________________________
  26.  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
  27.  |
  28.  |   $Revision: 1.1009 $
  29.  |
  30.  |   Description:
  31.  |    This file contains The MyColorWheel class, which lets you 
  32.  |  interactively select colors using a color wheel. 
  33.  |
  34.  |   Author(s)    : Alain Dumesny
  35.  |
  36.  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
  37.  _______________________________________________________________________
  38.  */
  39.  
  40. #ifndef  _SO_XT_COLOR_WHEEL_
  41. #define  _SO_XT_COLOR_WHEEL_
  42.  
  43. #include <Inventor/SbColor.h>
  44. #include <Inventor/SbLinear.h>
  45. #include <Inventor/misc/SoCallbackList.h>
  46. #include <Inventor/Xt/SoXtGLWidget.h>
  47.  
  48. class SoXtMouse;
  49.  
  50. // callback function prototypes
  51. typedef void MyColorWheelCB(void *userData, const float hsv[3]);
  52.                        
  53. //////////////////////////////////////////////////////////////////////////////
  54. //
  55. //  Class: MyColorWheel
  56. //
  57. //    Lets you interactively select colors using a color wheel. User register
  58. //  callback(s) to be notified when a new color has been selected. There is
  59. //  also a call to tell the color wheel what the current color is when it is
  60. //  changed externally.
  61. //
  62. //////////////////////////////////////////////////////////////////////////////
  63.  
  64. // C-api: prefix=SoXtColWhl
  65. class MyColorWheel : public SoXtGLWidget {
  66.  
  67.   public:
  68.     
  69.     MyColorWheel(
  70.     Widget parent = NULL,
  71.     const char *name = NULL, 
  72.     SbBool buildInsideParent = TRUE);
  73.     ~MyColorWheel();
  74.     
  75.     //
  76.     // Routine to tell the color wheel what the current HSV color is.
  77.     //
  78.     // NOTE: if calling setBaseColor() changes the marker position the
  79.     // valueChanged callbacks will be called with the new hsv color.
  80.     //
  81.     // C-api: name=setBaseCol
  82.     void        setBaseColor(const float hsv[3]);
  83.     // C-api: name=getBaseCol
  84.     const float *getBaseColor()         { return hsvColor; }
  85.     
  86.     //
  87.     // This routine sets the WYSIWYG (What You See Is What You Get) mode.
  88.     // When WYSIWYG is on the colors on the wheel will reflect the current
  89.     // color intensity (i.e. get darker and brighter)
  90.     //
  91.     void    setWYSIWYG(SbBool trueOrFalse);    // default FALSE
  92.     SbBool      isWYSIWYG()             { return WYSIWYGmode; }
  93.     
  94.     //
  95.     // Those routines are used to register callbacks for the different 
  96.     // color wheel actions.
  97.     //
  98.     // NOTE: the start and finish callbacks are only to signal when the mouse
  99.     // goes down and up. No valid callback data is passed (NULL passed).
  100.     //
  101.     // C-api: name=addStartCB
  102.     void    addStartCallback(
  103.             MyColorWheelCB *f,
  104.             void *userData = NULL)
  105.         { startCallbacks->addCallback((SoCallbackListCB *) f, userData); }
  106.  
  107.     // C-api: name=addValueChangedCB
  108.     void    addValueChangedCallback(
  109.             MyColorWheelCB *f, 
  110.             void *userData = NULL)
  111.         { changedCallbacks->addCallback((SoCallbackListCB *) f, userData); }
  112.     
  113.     // C-api: name=addFinishCB
  114.     void    addFinishCallback(
  115.             MyColorWheelCB *f,
  116.             void *userData = NULL)
  117.         { finishCallbacks->addCallback((SoCallbackListCB *) f, userData); }
  118.                        
  119.     // C-api: name=removeStartCB
  120.     void    removeStartCallback(
  121.             MyColorWheelCB *f,
  122.             void *userData = NULL)
  123.         { startCallbacks->removeCallback((SoCallbackListCB *) f, userData); }
  124.  
  125.     // C-api: name=removeValueChangedCB
  126.     void    removeValueChangedCallback(
  127.             MyColorWheelCB *f,
  128.             void *userData = NULL)
  129.         { changedCallbacks->removeCallback((SoCallbackListCB *) f, userData); }
  130.  
  131.     // C-api: name=removeFinishCB
  132.     void    removeFinishCallback(
  133.             MyColorWheelCB *f,
  134.             void *userData = NULL)
  135.         { finishCallbacks->removeCallback((SoCallbackListCB *) f, userData); }
  136.     
  137.     
  138.     // true while the color is changing interactively
  139.     SbBool  isInteractive()                     { return interactive; }
  140.  
  141.   protected:  
  142.  
  143.     // This constructor takes a boolean whether to build the widget now.
  144.     // Subclasses can pass FALSE, then call MyColorWheel::buildWidget()
  145.     // when they are ready for it to be built.
  146.     SoEXTENDER
  147.     MyColorWheel(
  148.     Widget parent,
  149.     const char *name, 
  150.     SbBool buildInsideParent, 
  151.     SbBool buildNow);
  152.  
  153.     Widget        buildWidget(Widget parent);
  154.  
  155.   private:
  156.     
  157.     // redefine these to do color wheel specific things
  158.     virtual void    redraw();
  159.     virtual void    redrawOverlay();
  160.     virtual void    processEvent(XAnyEvent *anyevent);
  161.     virtual void    initOverlayGraphic();
  162.     virtual void    sizeChanged(const SbVec2s &newSize);
  163.     
  164.     // color wheels local variables
  165.     SbBool    WYSIWYGmode;
  166.     SbBool    blackMarker;
  167.     float    hsvColor[3];
  168.     short    cx, cy, radius;
  169.     SbColor    *defaultColors, *colors;
  170.     SbVec2f    *geometry;
  171.     SoXtMouse    *mouse;
  172.     
  173.     // callback variables
  174.     SoCallbackList *startCallbacks;
  175.     SoCallbackList *changedCallbacks;
  176.     SoCallbackList *finishCallbacks;
  177.     SbBool      interactive;
  178.     
  179.     // routines to make the wheel geometry, colors, draw it....
  180.     void    makeWheelGeometry();
  181.     void    makeWheelColors(SbColor *col, float intensity);
  182.     void    drawWheelSurrounding();
  183.     void    drawWheelColors();
  184.     void    checkMarkerColor();
  185.     void    drawWheelMarker();
  186.     void    moveWheelMarker(short x, short y);
  187.  
  188.     // this is called by both constructors
  189.     void constructorCommon(SbBool buildNow);
  190. };
  191.  
  192.  
  193. #endif  /* _SO_XT_COLOR_WHEEL_ */
  194.